home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
os2tools
/
bnklysrc
/
b_search.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-13
|
14KB
|
371 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software <no-Inc> */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / No-Cost<no-tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
/* */
/* */
/* This module was written by Vince Perriello */
/* */
/* */
/* BinkleyTerm Phone list Search Module */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
/* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
/* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
/* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
/* ARE ABLE TO REACH WITH THE AUTHORS. */
/* */
/* */
/* The Authors can be reached at the following addresses: */
/* */
/* Robert C. Hartman Vincent E. Perriello */
/* Spark Software VEP Software */
/* 427-3 Amherst Street 111 Carroll Street */
/* CS2032, Suite 232 Naugatuck, CT 06770 */
/* Nashua, NH 03061 */
/* */
/* FidoNet 1:132/101 FidoNet 1:141/491 */
/* Data (603) 888-8179 Data (203) 729-7569 */
/* */
/* Please feel free to contact us at any time to share your comments */
/* about our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#ifdef __TURBOC__
#include <alloc.h>
#else
#include <malloc.h>
#endif
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "externs.h"
#include "prototyp.h"
static int SaveScanList (int);
static void wait_for_keypress(void);
int list_search ()
{
int saved_baud;
long t1, timerset ();
int i, k, l;
int dirty;
int zone, net, node, point;
unsigned int kbd_input;
static unsigned int save_chars[] = {
SHF1, SHF2, SHF3, SHF4, SHF5,
SHF6, SHF7, SHF8, SHF9, SHF10
};
static unsigned int load_chars[] = {
ALTF1, ALTF2, ALTF3, ALTF4, ALTF5,
ALTF6, ALTF7, ALTF8, ALTF9, ALTF10
};
static unsigned int command_chars[] = {
PF1, PF2, PF3, PF4, PF5,
PF6, PF7, PF8, PF9, PF10
};
/*
* * Input the phone numbers we want to scan *
*
*/
dirty = 1;
for (;;)
{
if (dirty)
{
cprintf ("\033[H\033[J\r\n");
cprintf ("F1 ... F10 = input phone number, (ENTER) = start, (ESC) = abort\r\n");
cprintf ("ALT-Fn = load saved set (n), Shift-Fn = save into set (n)\r\n");
cprintf ("Phone Numbers currently Selected:\r\n\r\n");
for (k = 0; k < 10; k += 2)
{
cprintf ("%2d: %35s %2d: %35s\r\n",
k + 1, scan_list[k], k + 2, scan_list[k + 1]);
}
cprintf ("\r\nInput Command: ");
dirty = 0;
}
while (!KEYPRESS ())
time_release ();
kbd_input = FOSSIL_CHAR ();
if (((kbd_input & 0xff) == '\n') || ((kbd_input & 0xff) == '\r'))
break;
if ((kbd_input & 0xff) == ESC)
return (0);
for (k = 0; k < 10; k++)
{
if (kbd_input == save_chars[k]) /* Save into a set? */
{
SaveScanList(k); /* Yes, do it */
dirty = 1; /* Force redisplay */
k = 10; /* Then fool the logic*/
break;
}
if (kbd_input == load_chars[k]) /* Load from a set? */
{
LoadScanList(k,1); /* Yes, do it */
dirty = 1; /* Force redisplay */
k = 10; /* Then fool the logic*/
break;
}
if (kbd_input == command_chars[k]) /* Plain old Fkey? */
break; /* Yup, get out now */
}
if (k == 10) /* Not a function key */
{
k = (kbd_input & 0xff) - '0'; /* Convert from digit */
if ((k < 0) || (k > 9)) /* Was it a digit? */
continue; /* No, throw char out */
if (!k) /* Is it a zero? */
k = 9; /* That's 9 to us */
else --k; /* Else make zero-rel */
}
cprintf ("Element Chosen = %2d\r\n", k + 1);
if (scan_list[k] != NULL)
{
cprintf ("Currently contains %s\r\n", scan_list[k]);
cprintf ("(ENTER) = save, (space)(ENTER) = delete, or enter new number:\r\n");
}
else
{
cprintf ("(ENTER) or (space)(ENTER) = cancel, or enter new number:\r\n");
}
gets (junk); /* Get the user's input */
++dirty; /* Always redisplay */
if ((l = strlen (junk)) == 0) /* If nothing there, */
continue; /* move along */
if (l == 1 && *junk == ' ') /* If just a space... */
{
if (scan_list[k] != NULL) /* Delete old number */
free (scan_list[k]);
scan_list[k] = NULL; /* Clean up the ref */
/* ++dirty; *//* Force a redisplay */
continue; /* End this iteration */
}
if (scan_list[k] != NULL) /* Get rid of old num */
free (scan_list[k]);
if ((scan_list[k] = malloc (++l)) == NULL) /* Allocate space */
{
cprintf ("\r\nUnable to allocate space for number!\r\n");
return (0); /* Get out for error */
}
strcpy (scan_list[k], junk); /* Save new number */
/* ++dirty; *//* Force a redisplay */
}
/*
* * Actual Search logic *
*
*/
status_line ("#Starting Phone List Scan");
for (;;)
{
l = 0;
for (k = 0; k < 10; k++)
{
if (scan_list[k] == NULL)
continue;
strcpy (junk, scan_list[k]);
if (!isdigit (junk[0]) && junk[0] != '\"')
{
fidouser (junk, &zone, &net, &node, &point);
if ((net != -1) && (node != -1) && (zone != -1))
{
if (zone == alias[0].Zone)
sprintf (junk, "%d/%d", net, node);
else sprintf (junk, "%d:%d/%d", zone, net, node);
}
else continue;
}
if (strchr (junk, '/') != NULL)
{
if (!nodeproc (junk))
break;
strcpy (junk, newnodedes.PhoneNumber);
}
caller = 0;
saved_baud = baud;
if (try_1_connect (junk)) /* Attempt to connect */
{
status_line ("#Connected to list element %d", k + 1);
free (scan_list[k]);
scan_list[k] = NULL;
gong ();
return (1);
}
++l;
baud = saved_baud;
MDM_ENABLE (btypes[baud].rate);
cur_baud = atoi (btypes[baud].str);
t1 = timerset (200);
while (!timeup (t1)) /* pause for 2 seconds */
{
if (KEYPRESS ())
{
i = FOSSIL_CHAR () & 0xff;
if (i == ESC) /* Abort for ESCape */
{
status_line ("!Connection attempt aborted");
return (0);
}
}
time_release ();
}
}
if (!l)
return (0);
}
}
LoadScanList(number,report_errors)
int number; /* Set number to load */
int report_errors; /* Whether to report */
{
int k, l;
FILE *ScanFile;
sprintf(junk,"%sBinkScan.LS%c",BINKpath, number + '0');
if ((ScanFile = fopen(junk, "rb")) == NULL)
{
if (report_errors)
{
cprintf("Could not open %s\r\n",junk);
wait_for_keypress();
}
return(0);
}
for (k = 0; k < 10; k++)
{
if (fread(junk, 36, 1, ScanFile) != 1)
{
if (report_errors)
{
cprintf("Error reading data from set %d\r\n", number + 1);
wait_for_keypress();
}
fclose(ScanFile);
return(0);
}
if (scan_list[k] != NULL)
{
free(scan_list[k]);
scan_list[k] = NULL;
}
if (l = strlen(junk))
{
if ((scan_list[k] = malloc (++l)) == NULL) /* Allocate space */
{
if (report_errors)
{
cprintf("Unable to allocate space for set %d\r\n", number + 1);
wait_for_keypress();
}
fclose(ScanFile);
return(0);
}
strcpy (scan_list[k], junk); /* Save new number */
}
}
l = fclose (ScanFile);
if (report_errors)
{
if (l)
cprintf("Error closing file for set %d\r\n", number + 1);
else
cprintf("Set %d successfully loaded.\r\n", number + 1);
wait_for_keypress();
}
return(l);
}
static SaveScanList(number)
int number; /* Set number to save */
{
int k, l;
FILE *ScanFile;
sprintf(junk,"%sBinkScan.LS%c",BINKpath, number + '0');
if ((ScanFile = fopen(junk, "wb")) == NULL)
{
cprintf("Could not open %s\r\n",junk);
wait_for_keypress();
return(0);
}
for (k = 0; k < 10; k++)
{
for (l = 0; l < 36; l++)
junk[l] = '\0';
if (scan_list[k] != NULL)
strcpy(junk,scan_list[k]);
if (fwrite(junk, 36, 1, ScanFile) != 1)
{
cprintf("Error writing data to set %d\r\n", number + 1);
wait_for_keypress();
fclose(ScanFile);
return(0);
}
}
if (l = fclose(ScanFile))
cprintf("Error closing file for set %d\r\n", number + 1);
else
cprintf("Current list of numbers saved to set %d\r\n", number + 1);
wait_for_keypress();
return(l);
}
static void wait_for_keypress(void)
{
cprintf("Press any key to continue.\r\n");
while (!KEYPRESS ())
time_release ();
FOSSIL_CHAR ();
}